package com.itcast.springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //客户端连接端点
        registry.addEndpoint("/websocket")
                .setAllowedOrigins("*")
                .withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //原生Broker配置：只允许前缀是topic和queue的主题
        registry.enableSimpleBroker("/topic/", "/queue/");
        //默认单发发布的前缀是user，将user改为queue
        registry.setUserDestinationPrefix("/queue/");
//
////        //给前端的请求路径添加指定前缀
////        registry.setApplicationDestinationPrefixes("/app");
//
//        /**
//         * rabbitMq
//         */
////        //注册rabbitmq的Broker，默认前缀是topic，queue，exchange
////        registry.enableStompBrokerRelay("/topic/", "/queue/", "/exchange/")
////                .setRelayHost("localhost")
////                .setRelayPort(61613)
////                .setClientLogin("guest")
////                .setClientPasscode("guest")
////                .setVirtualHost("/");
////        //给前端的请求路径添加指定前缀
////        registry.setApplicationDestinationPrefixes("/app");
    }
}
